/**
 * @program: LeetCode
 * @description: LeetCode : 剑指 Offer II 032. 有效的变位词
 * @author: WXY
 * @create: 2022-12-18 10:08
 * @Version 1.0
 **/


public class Num_offer2_032_isAnagram {
    public static boolean isAnagram(String s, String t) {
        if (s == null && t == null) {
            return true;
        }
        if (s.length() != t.length()) {
            return false;
        }
        int len = s.length();
        char[] strS = s.toCharArray();
        char[] strT = t.toCharArray();
        boolean flag = false;
        for (int i = 0; i < len; i++) {
            if (strS[i] != strT[i]) {
                flag = true;
            }
        }
        if (flag == false) return false;
        int[] arr = new int[26];
        for (int i = 0; i < s.length(); i++) {
            arr[s.charAt(i) - 'a']++;
        }
        for (int i = 0; i < t.length(); i++) {
            arr[t.charAt(i) - 'a']--;
        }
        for (int i = 0; i < 26; i++) {
            if (arr[i] != 0) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        String s = "a";
        String t = "a";
        boolean anagram = isAnagram(s, t);
        System.out.println(anagram);
    }
}
